package com.cf.oss.core;

/**
 * game-server-OSSBatchResult
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/6/5 下午 12:01
 */


import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class OSSBatchResult<R, T> {
    private List<OperationPair<R, T>> successList;
    private List<R> failedList;

    public OSSBatchResult() {
    }

    public OSSBatchResult<R, T> addSuccessOne(R request, T response) {
        if (this.successList == null) {
            this.successList = new LinkedList();
        }

        this.successList.add(new OperationPair(request, response));
        return this;
    }

    public OSSBatchResult<R, T> addFailedOne(R request) {
        if (this.failedList == null) {
            this.failedList = new LinkedList();
        }

        this.failedList.add(request);
        return this;
    }

    public boolean isAllSuccess() {
        return CollectionUtils.isEmpty(this.failedList);
    }

    public List<OperationPair<R, T>> getSuccessList() {
        return CollectionUtils.isEmpty(this.successList) ? Collections.EMPTY_LIST : this.successList;
    }

    public List<R> getFailedList() {
        return CollectionUtils.isEmpty(this.failedList) ? Collections.EMPTY_LIST : this.failedList;
    }

    public static class OperationPair<R, T> {
        private R request;
        private T response;

        public OperationPair(R request, T response) {
            this.request = request;
            this.response = response;
        }

        public R getRequest() {
            return this.request;
        }

        public T getResponse() {
            return this.response;
        }
    }
}
